package bestfriends.tamu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;


 
public class Question implements Comparator<Result>{
	String text;
	ArrayList <Result> result;
	
	public Question(){
		//default constructor
	}
	
	public Question(String new_text, ArrayList<Result> res) {
		text = new_text;
		result = res;
	}
	
	public void setQuestionText(String new_text){
		text = new_text;
	}
	
	public void setResult(ArrayList<Result> res){
		result = res;
	}
	
	public String getQuestionText(){
		return text;
	}
	
	public ArrayList<Result> getResult(){
		return result;
	}
	
	public void sortResults(){
		Collections.sort(this.result);
	}

	@Override
	public int compare(Result arg0, Result arg1) {
		if(arg0.appearances > 0 && arg1.appearances > 0) {
			double val = arg0.wins/arg0.appearances - arg1.wins/arg1.appearances;
			if(val > 0) {
				return 1;
			} else {
				return -1;
			}
		} else if (arg1.appearances > 0) {
			return -1;
		} else {
			return 1;
		}
	}
}